package cn.fy.sharedpreferences.activity;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.viewpager2.adapter.FragmentStateAdapter;

import android.os.Bundle;

import java.util.ArrayList;
import java.util.List;

import cn.fy.sharedpreferences.databinding.ActivityGuideBinding;
import cn.fy.sharedpreferences.fragment.Frag1Fragment;
import cn.fy.sharedpreferences.fragment.Frag2Fragment;
import cn.fy.sharedpreferences.fragment.Frag3Fragment;

public class GuideActivity extends AppCompatActivity {

    private ActivityGuideBinding binding;

    List<Class> fragmentList = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.activity_guide);
        binding = ActivityGuideBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());


        fragmentList.add(Frag1Fragment.class);
        fragmentList.add(Frag2Fragment.class);
        fragmentList.add(Frag3Fragment.class);

        binding.vp.setAdapter(new FragmentStateAdapter(this) {
            @NonNull
            @Override
            public Fragment createFragment(int position) {
                try {
                    return (Fragment) fragmentList.get(position).newInstance();
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                } catch (InstantiationException e) {
                    e.printStackTrace();
                }
                return null;
            }

            @Override
            public int getItemCount() {
                return fragmentList.size();
            }
        });

    }
}